#include <iostream>
using namespace std;

typedef struct _tree_node {
	int value;
	struct _tree_node* left;
	struct _tree_node* right;

	_tree_node(int val) {
		value = val;
		left = NULL;
		right = NULL;
	}
}tree_node;

tree_node* get_tree() {
	tree_node* r0 = new tree_node(3);
	tree_node* r1 = new tree_node(1);
	tree_node* r2 = new tree_node(5);
	tree_node* r3 = new tree_node(0);
	tree_node* r4 = new tree_node(2);
	tree_node* r5 = new tree_node(4);

	r0->left = r1;
	r0->right = r2;
	r1->left = r3;
	r1->right = r4;
	r2->left = r5;

	return r0;
}

void get_list(tree_node* root, tree_node** last) {
	if (root == NULL)
		return;

	tree_node* current = root;

	if (current->left != NULL) 
		 get_list(current->left, last);
	
	current->left = *last;
	if (*last != NULL)
		(*last)->right = current;

	*last = current;
	if (current->right != NULL)
		get_list(current->right, last);
}

tree_node* get_list(tree_node* root) {
	tree_node* last = NULL;
	get_list(root, &last);

	return last;
}

//int main() {
//	tree_node* tree = get_tree();
//	tree_node* list = get_list(tree);
//	
//	return 0;
//}